﻿using System.Drawing;

namespace XYAC.Framework.MonitorTireMaterialManual.DataExporter
{
    /// <summary>
    /// 表示自定义测量类，继承自 Measuring 基类。
    /// </summary>
    public class ClsMyMeasuring : Measuring
    {
        /// <summary>
        /// 测量结果。
        /// </summary>
        private MeasureResult m_result;

        /// <summary>
        /// 获取或设置测量结果。
        /// </summary>
        public MeasureResult MeasureResult
        {
            get
            {
                return m_result;
            }
            set
            {
                m_result = value;
            }
        }

        /// <summary>
        /// 班组信息。
        /// </summary>
        private string m_BanZu;

        /// <summary>
        /// 获取或设置班组信息。
        /// </summary>
        public string BanZu
        {
            get
            {
                return m_BanZu;
            }
            set
            {
                m_BanZu = value;
            }
        }

        /// <summary>
        /// 宽度间隔。
        /// </summary>
        private float m_IntervalWidth;

        /// <summary>
        /// 获取或设置宽度间隔。
        /// </summary>
        public float IntervalWidth
        {
            get { return m_IntervalWidth; }
            set { m_IntervalWidth = value; }
        }

        /// <summary>
        /// 报警点列表。
        /// </summary>
        private List<MyAlarmPoints> m_AlarmPoints = new List<MyAlarmPoints>();

        /// <summary>
        /// 获取或设置报警点列表。
        /// </summary>
        public List<MyAlarmPoints> AlarmPoints
        {
            get { return m_AlarmPoints; }
            set { m_AlarmPoints = value; }
        }

        /// <summary>
        /// 获取报警点列表的字符串表示形式，使用 * 作为分隔符。
        /// </summary>
        public string AlarmPointsStr
        {
            get { return AlarmPointsToStr(); }
        }

        /// <summary>
        /// 初始化 ClsMyMeasuring 类的新实例。
        /// </summary>
        /// <param name="MeasurData">测量数据列表。</param>
        /// <param name="XInterval">X轴间隔。</param>
        public ClsMyMeasuring(List<MeasurData> MeasurData, float XInterval)
            : base(MeasurData, XInterval)
        {
            m_IntervalWidth = XInterval;
        }

        /// <summary>
        /// 初始化 ClsMyMeasuring 类的新实例，包含测量结果。
        /// </summary>
        /// <param name="MeasurData">测量数据列表。</param>
        /// <param name="XInterval">X轴间隔。</param>
        /// <param name="Result">测量结果。</param>
        public ClsMyMeasuring(List<MeasurData> MeasurData, float XInterval, MeasureResult Result)
            : base(MeasurData, XInterval)
        {
            m_IntervalWidth = XInterval;
            m_result = Result;
        }

        /// <summary>
        /// 将关键点列表转换为字符串表示，使用 * 作为分隔符。
        /// </summary>
        /// <returns>关键点的字符串表示。</returns>
        public string KeyPointsToStr()
        {
            string str = "";
            if (KeyPoints == null) return str;
            PointData m_Point = new PointData(new PointF(0, 0));
            for (int i = 0; i < KeyPoints.Count; i++)
            {
                m_Point = KeyPoints[i];
                if (i == 0)
                    str = m_Point.Point.X.ToString("0.00") + "#" + m_Point.Point.Y.ToString("0.00") + "#" + m_Point.XOffset.ToString() + "#" + m_Point.YOffset.ToString();
                else
                    str = str + "*" + m_Point.Point.X.ToString("0.00") + "#" + m_Point.Point.Y.ToString("0.00") + "#" + m_Point.XOffset.ToString() + "#" + m_Point.YOffset.ToString();
            }
            return str;
        }

        /// <summary>
        /// 从字符串解析出关键点列表，使用 * 作为分隔符。
        /// </summary>
        /// <param name="Str">包含关键点数据的字符串。</param>
        /// <returns>解析出的关键点列表。</returns>
        public static PointDataList KeyPointsFromStr(string Str)
        {
            string[] s = Str.Split('*');
            PointDataList m_KeyPoints = new PointDataList();
            PointData kp = new PointData(new PointF(0, 0), 0, 0);
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != "")
                {
                    kp = (PointData)NominalDataHanding.PointDataFromStr(s[i], false);
                    m_KeyPoints.Add(kp);
                }
            }
            return m_KeyPoints;
        }

        /// <summary>
        /// 从字符串解析出高度列表，使用 * 作为分隔符。
        /// </summary>
        /// <param name="Str">包含高度数据的字符串。</param>
        /// <returns>解析出的高度列表。</returns>
        public static List<float> HeightListFromStr(string Str)
        {
            List<float> SingleList = new List<float>();
            string[] v = Str.Split('*');
            for (int n = 0; n < v.Length; n++)
            {
                if (v[n] != "")
                    SingleList.Add(Convert.ToSingle(v[n]));
            }
            return SingleList;
        }

        /// <summary>
        /// 将高度列表转换为字符串表示，使用 * 作为分隔符。
        /// </summary>
        /// <returns>高度列表的字符串表示。</returns>
        public string HeightListToStr()
        {
            string str = "";
            for (int i = 0; i < m_ThicknessPoints.Count; i++)
            {
                str = str + m_ThicknessPoints[i].Point.Y.ToString("f2") + "*";
            }
            return str;
        }

        /// <summary>
        /// 从字符串解析出底部高度列表，使用 * 作为分隔符。
        /// </summary>
        /// <param name="Str">包含底部高度数据的字符串。</param>
        /// <returns>解析出的底部高度列表。</returns>
        public static List<float> BottomListFromStr(string Str)
        {
            List<float> SingleList = new List<float>();
            string[] v = Str.Split('*');
            for (int n = 0; n < v.Length; n++)
            {
                if (v[n] != "")
                    SingleList.Add(Convert.ToSingle(v[n]));
            }
            return SingleList;
        }

        /// <summary>
        /// 将底部高度列表转换为字符串表示，使用 * 作为分隔符。
        /// </summary>
        /// <returns>底部高度列表的字符串表示。</returns>
        public string BottomListToStr()
        {
            string str = "";
            for (int i = 0; i < m_BottomHeightPoints.Count; i++)
            {
                str = str + m_BottomHeightPoints[i].Point.Y.ToString("f2") + "*";
            }
            return str;
        }

        /// <summary>
        /// 将报警点列表转换为字符串表示，使用 * 作为分隔符。
        /// </summary>
        /// <returns>报警点列表的字符串表示。</returns>
        public string AlarmPointsToStr()
        {
            string str = "";
            if (AlarmPoints == null) return str;
            for (int i = 0; i < AlarmPoints.Count; i++)
            {
                if (i == 0)
                    str = AlarmPoints[i].NominalKeyPoint.Point.X.ToString() + "#" + AlarmPoints[i].NominalKeyPoint.Point.Y.ToString() + "#" + AlarmPoints[i].NominalKeyPoint.XOffset.ToString() + "#"
                        + AlarmPoints[i].NominalKeyPoint.YOffset.ToString() + "#" + string.Format("{0:f2}", AlarmPoints[i].MeasuringKeyPoint.Point.X) + "#" + string.Format("{0:f2}", AlarmPoints[i].MeasuringKeyPoint.Point.Y) + "#"
                        + string.Format("{0:f2}", AlarmPoints[i].DiffKeyPoint.Point.X) + "#" + string.Format("{0:f2}", AlarmPoints[i].DiffKeyPoint.Point.Y);
                else
                    str = str + "*" + AlarmPoints[i].NominalKeyPoint.Point.X.ToString() + "#" + AlarmPoints[i].NominalKeyPoint.Point.Y.ToString() + "#" + AlarmPoints[i].NominalKeyPoint.XOffset.ToString() + "#"
                        + AlarmPoints[i].NominalKeyPoint.YOffset.ToString() + "#" + string.Format("{0:f2}", AlarmPoints[i].MeasuringKeyPoint.Point.X) + "#" + string.Format("{0:f2}", AlarmPoints[i].MeasuringKeyPoint.Point.Y) + "#"
                        + string.Format("{0:f2}", AlarmPoints[i].DiffKeyPoint.Point.X) + "#" + string.Format("{0:f2}", AlarmPoints[i].DiffKeyPoint.Point.Y);
            }
            return str;
        }

        /// <summary>
        /// 将测量结果转换为字符串表示。
        /// </summary>
        /// <returns>测量结果的字符串表示。</returns>
        public string MeasureResultToStr()
        {
            string str = "";
            str = MeasureResult.BResult.ToString() + "#" + MeasureResult.OkPoints.ToString() + "#" + MeasureResult.TotalPoints.ToString()
                + "#" + MeasureResult.FPercent.ToString() + "#" + MeasureResult.AlarmType.ToString();
            return str;
        }

        /// <summary>
        /// 从字符串解析测量结果。
        /// </summary>
        /// <param name="Str">包含测量结果数据的字符串。</param>
        /// <returns>解析出的测量结果对象。</returns>
        public static MeasureResult MeasureResultFromStr(string Str)
        {
            MeasureResult mr = new MeasureResult();
            string[] v = Str.Split('#');
            if (v.Length == 5)
            {
                if (v[0] != "")
                    mr.BResult = bool.Parse(v[0]);
                if (v[1] != "")
                    mr.OkPoints = int.Parse(v[1]);
                if (v[2] != "")
                    mr.TotalPoints = int.Parse(v[2]);
                if (v[3] != "")
                    mr.FPercent = float.Parse(v[3]);
                if (v[4] != "")
                    mr.AlarmType = int.Parse(v[4]);
            }
            return mr;
        }

        /// <summary>
        /// 实际重量。
        /// </summary>
        protected float m_Weight;

        /// <summary>
        /// 获取或设置实际重量。
        /// </summary>
        public float Weight
        {
            get
            {
                return m_Weight;
            }
            set
            {
                m_Weight = value;
            }
        }

        /// <summary>
        /// 设定重量。
        /// </summary>
        protected float m_SetWeight;

        /// <summary>
        /// 获取或设置设定重量。
        /// </summary>
        public float SetWeight
        {
            get
            {
                return m_SetWeight;
            }
            set
            {
                m_SetWeight = value;
            }
        }

        /// <summary>
        /// 重量上公差。
        /// </summary>
        protected float m_UpWeight;

        /// <summary>
        /// 获取或设置重量上公差。
        /// </summary>
        public float UpWeight
        {
            get
            {
                return m_UpWeight;
            }
            set
            {
                m_UpWeight = value;
            }
        }

        /// <summary>
        /// 重量下公差。
        /// </summary>
        protected float m_DownWeight;

        /// <summary>
        /// 获取或设置重量下公差。
        /// </summary>
        public float DownWeight
        {
            get
            {
                return m_DownWeight;
            }
            set
            {
                m_DownWeight = value;
            }
        }

        /// <summary>
        /// 速度。
        /// </summary>
        protected float m_Seep;

        /// <summary>
        /// 获取或设置速度。
        /// </summary>
        public float Seep
        {
            get
            {
                return m_Seep;
            }
            set
            {
                m_Seep = value;
            }
        }

        /// <summary>
        /// 输出长度。
        /// </summary>
        protected float m_OutLong;

        /// <summary>
        /// 获取或设置输出长度。
        /// </summary>
        public float OutLong
        {
            get
            {
                return m_OutLong;
            }
            set
            {
                m_OutLong = value;
            }
        }
    }

}
